import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "dashboard" }
      }
    ]
  },
  {
    path: "/message",
    component: Layout,
    redirect: "/message",
    hidden: true,
    children: [
      {
        path: "messageList",
        name: "message",
        component: () => import("@/views/message/messageList"),
        meta: { title: "消息通知", icon: "dashboard" }
      }
    ]
  },
  {
    path: "/detail",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "oldDetail",
        name: "OldDetail",
        hidden: true,
        component: () => import("@/views/oldDetail/index"),
        meta: {
          title: "老人详情",
          icon: "form",
          activeMenu: "/example/project"
        }
      },
      {
        path: "projectDetail",
        name: "ProjectDetail",
        hidden: true,
        component: () => import("@/views/projectDetail/index"),
        meta: {
          title: "项目详情",
          icon: "form",
          activeMenu: "/projectManager/project"
        }
      },
      {
        path: "constructionDetail",
        name: "ConstructionDetail",
        hidden: true,
        component: () => import("@/views/constructionDetail/index"),
        meta: {
          title: "施工详情",
          icon: "form",
          activeMenu: "/example/construction"
        }
      },
      {
        path: "constructionDetailing",
        name: "ConstructionDetailing",
        hidden: true,
        component: () => import("@/views/constructionDetailing/index"),
        meta: {
          title: "施工详情",
          icon: "form",
          activeMenu: "/example/construction"
        }
      }
    ]
  },
  {
    path: "/oldManager",
    component: Layout,
    redirect: "/oldManager/old",
    name: "OldManager",
    meta: { title: "老人管理", icon: "el-icon-s-help" },
    children: [
      {
        path: "old",
        name: "Old",
        component: () => import("@/views/old/index"),
        meta: { title: "老人管理", icon: "el-icon-date" }
      }
      // {
      //   path: "assessment",
      //   name: "Assessment",
      //   component: () => import("@/views/assessment/index"),
      //   meta: { title: "审批批复", icon: "el-icon-date" }
      // },
      // {
      //   path: "task",
      //   name: "Task",
      //   component: () => import("@/views/task/index"),
      //   meta: { title: "老人档案", icon: "el-icon-tickets" }
      // }
    ]
  },
  {
    path: "/assess",
    component: Layout,
    name: "Assess",
    meta: { title: "评估管理", icon: "el-icon-s-help" },
    children: [
      {
        path: "assessment",
        name: "Assessment",
        component: () => import("@/views/assessment/index"),
        meta: { title: "评估管理", icon: "el-icon-date" }
      }
    ]
  },
  {
    path: "/contractManager",
    component: Layout,
    redirect: "/contractManager/contract",
    name: "ContractManager",
    meta: { title: "签约管理", icon: "el-icon-s-help" },
    children: [
      {
        path: "contract",
        name: "Contract",
        component: () => import("@/views/contract/index"),
        meta: { title: "合同管理", icon: "el-icon-date" }
      },
      {
        path: "contractTemplate",
        name: "ContractTemplate",
        component: () => import("@/views/contract/contractTemplate"),
        meta: { title: "合同模块维护", icon: "el-icon-date" }
      }
    ]
  },
  {
    path: "/transformation",
    component: Layout,
    redirect: "/transformation/project",
    name: "Example",
    meta: { title: "改造管理", icon: "el-icon-s-help" },
    children: [
      {
        path: "project",
        name: "Project",
        component: () => import("@/views/project/index"),
        meta: { title: "改造过程监管", icon: "el-icon-date" }
      }
      // {
      //   path: "assessment4",
      //   name: "Assessment",
      //   component: () => import("@/views/assessment/index"),
      //   meta: { title: "改造验收", icon: "el-icon-date" }
      // }
    ]
  },
  {
    path: "/service",
    component: Layout,
    redirect: "/service/call",
    name: "Service",
    meta: { title: "服务管理", icon: "el-icon-s-help" },
    children: [
      {
        path: "call",
        name: "Call",
        component: () => import("@/views/service/call"),
        meta: { title: "呼叫服务", icon: "el-icon-date" }
      },
      {
        path: "alarm",
        name: "Alarm",
        component: () => import("@/views/service/alarm"),
        meta: { title: "报警管理", icon: "el-icon-date" }
      },
      {
        path: "servicePlan",
        name: "ServicePlan",
        component: () => import("@/views/service/servicePlan"),
        meta: { title: "服务计划", icon: "el-icon-date" }
      },
      {
        path: "evaluation",
        name: "Evaluation",
        component: () => import("@/views/service/evaluation"),
        meta: { title: "服务评价", icon: "el-icon-date" }
      }
    ]
  },
  {
    path: "/financial",
    component: Layout,
    meta: { title: "财务管理", icon: "el-icon-s-help" },
    children: [
      {
        path: "serviceStatistics",
        name: "ServiceStatistics",
        component: () => import("@/views/financial/serviceStatistics"),
        meta: { title: "服务项目统计", icon: "form" }
      },
      {
        path: "reportStatistics",
        name: "ReportStatistics",
        component: () => import("@/views/financial/reportStatistics"),
        meta: { title: "消费报表统计", icon: "form" }
      },
      {
        path: "subsidy",
        name: "Subsidy",
        component: () => import("@/views/financial/subsidy"),
        meta: { title: "补贴管理", icon: "form" }
      }
    ]
  },
  {
    path: "/projectManager",
    component: Layout,
    meta: { title: "项目管理", icon: "el-icon-s-help" },

    children: [
      {
        path: "serviceManagement",
        name: "ServiceManagement",
        component: () => import("@/views/projectManager/serviceManagement"),
        meta: { title: "服务管理", icon: "el-icon-location-information" }
      },
      {
        path: "equipment",
        name: "Equipment",
        component: () => import("@/views/projectManager/equipment"),
        meta: { title: "设备管理", icon: "el-icon-location-information" }
      },
      {
        path: "package",
        name: "Package",
        component: () => import("@/views/projectManager/package"),
        meta: { title: "套餐配置", icon: "el-icon-location-information" }
      }
    ]
  },
  {
    path: "/system",
    component: Layout,
    redirect: "/system/user",
    name: "Nested",
    meta: {
      title: "系统管理",
      icon: "nested"
    },
    children: [
      {
        path: "mechanism",
        name: "Mechanism",
        component: () => import("@/views/system/mechanism"),
        meta: {
          title: "机构管理",
          icon: "el-icon-mobile-phone"
        }
      },
      {
        path: "dept",
        name: "Dept",
        component: () => import("@/views/system/dept"),
        meta: {
          title: "部门管理",
          icon: "el-icon-mobile-phone"
        }
      },
      {
        path: "staff",
        name: "Staff",
        component: () => import("@/views/system/staff"),
        meta: {
          title: "员工管理",
          icon: "el-icon-mobile-phone"
        }
      },
      {
        path: "account",
        component: () => import("@/views/system/account"), // Parent router-view
        name: "Account",
        meta: { title: "账号管理", icon: "el-icon-folder-opened" }
      },
      {
        path: "announcement",
        name: "Announcement",
        component: () => import("@/views/system/announcement"),
        meta: { title: "系统公告", icon: "el-icon-tickets" }
      }
    ]
  },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true }
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
